﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.Script.Serialization;
using FlexiGridHelper;

namespace Golf.WebUI.HttpHandler.Order
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary> 
    public class Golf_OrderList : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            JavaScriptSerializer js = new JavaScriptSerializer();
            Golf.BLL.Golf_Order bll = new Golf.BLL.Golf_Order();
            List<Golf.Model.Golf_Order> list = new List<Golf.Model.Golf_Order>();
            //实例化页面信息类，获取页面传来的参数。该类是FlexiGridHelper中定义的类，封装了很多功能需要的数据
            PageView pageView = new PageView(context);
            //获取分页后的数据集
            DataSet ds = bll.GetList(pageView.PageSize, pageView.PageIndex, "");
            //构建表格
            DataTable dt = new DataTable();
            //构建列
            //注意：第一列必须是数据库的主键列
            DataColumn dc0 = new DataColumn("Id", typeof(string));
            DataColumn dc1 = new DataColumn("OrderNumber", typeof(string));
            DataColumn dc2 = new DataColumn("OrderSumPrice", typeof(string));
            DataColumn dc3 = new DataColumn("UserId", typeof(string));
            DataColumn dc4 = new DataColumn("FristName", typeof(string));
            DataColumn dc5 = new DataColumn("LastName", typeof(string));
            DataColumn dc6 = new DataColumn("ProductSumPrice", typeof(string));
            DataColumn dc7 = new DataColumn("TransportationPrice", typeof(string));
            DataColumn dc8 = new DataColumn("MailTypeId", typeof(string));
            DataColumn dc9 = new DataColumn("IsCoupon", typeof(string));
            DataColumn dc10 = new DataColumn("CouponPrice", typeof(string));
            DataColumn dc11 = new DataColumn("IsAddPrice", typeof(string));
            DataColumn dc12 = new DataColumn("AddPriceState", typeof(string));
            DataColumn dc13 = new DataColumn("AddPrice", typeof(string));
            DataColumn dc14 = new DataColumn("ProductNumberList", typeof(string));
            DataColumn dc15 = new DataColumn("OrderGeneratedTime", typeof(string));
            DataColumn dc16 = new DataColumn("OrderVerifyTime", typeof(string));
            DataColumn dc17 = new DataColumn("VerifyNameId", typeof(string));
            DataColumn dc18 = new DataColumn("AddressId", typeof(string));
            DataColumn dc19 = new DataColumn("UserMessage", typeof(string));
            DataColumn dc20 = new DataColumn("UserIp", typeof(string));
            DataColumn dc21 = new DataColumn("IsPayment", typeof(string));
            DataColumn dc22 = new DataColumn("PaymentTypeId", typeof(string));
            DataColumn dc23 = new DataColumn("PaymentBankId", typeof(string));
            DataColumn dc24 = new DataColumn("PaymentPrice", typeof(string));
            DataColumn dc25 = new DataColumn("PaymentTime", typeof(string));
            DataColumn dc26 = new DataColumn("PaymentOrderNumber", typeof(string));
            DataColumn dc27 = new DataColumn("RefundTypeId", typeof(string));
            DataColumn dc28 = new DataColumn("LogisticsStateId", typeof(string));
            DataColumn dc29 = new DataColumn("Logisticsnumber", typeof(string));
            DataColumn dc30 = new DataColumn("PenskeLogistics", typeof(string));
            DataColumn dc31 = new DataColumn("LogisticsRemarks", typeof(string));
            DataColumn dc32 = new DataColumn("OrderStateCodeId", typeof(string));
            DataColumn dc33 = new DataColumn("ProductOrderNumber", typeof(string));
            DataColumn dc34 = new DataColumn("IsDeliver", typeof(string));
            DataColumn dc35 = new DataColumn("DeliverTime", typeof(string));
            DataColumn dc36 = new DataColumn("DeliverUnitId", typeof(string));
            DataColumn dc37 = new DataColumn("IsPrintDeliver", typeof(string));
            DataColumn dc38 = new DataColumn("AllocateUnitId", typeof(string));
            DataColumn dc39 = new DataColumn("AllocateTime", typeof(string));
            DataColumn dc40 = new DataColumn("AdminMessageId", typeof(string));
            DataColumn dc41 = new DataColumn("IsShow", typeof(string));
            DataColumn dc42 = new DataColumn("Pro_AttrList", typeof(string));
            //把构建的列添加到数据表中
            dt.Columns.AddRange(new DataColumn[] { dc0, dc1, dc2, dc3, dc4, dc5, dc6, dc7, dc8, dc9, dc10, dc11, dc12, dc13, dc14, dc15, dc16, dc17, dc18, dc19, dc20, dc21, dc22, dc23, dc24, dc25, dc26, dc27, dc28, dc29, dc30, dc31, dc32, dc33, dc34, dc35, dc36, dc37, dc38, dc39, dc40, dc41,dc42 });//这里有个顺序的哟 
            list = bll.DataTableToList(ds.Tables[0]);//获取第一张表的数据  就是数据库中的数据
            //填充数据
            foreach (var item in list)
            {
                //新建行，注意是dt.NewRow();而不是new DataRow();
                DataRow dr = dt.NewRow();
                dt.Rows.Add(dr);
                dr["Id"] = item.Id;
                dr["OrderNumber"] = item.OrderNumber;
                dr["OrderSumPrice"] = item.OrderSumPrice;
                dr["UserId"] = item.UserId;
                dr["FristName"] = item.FristName;
                dr["LastName"] = item.LastName;
                dr["ProductSumPrice"] = item.ProductSumPrice;
                dr["TransportationPrice"] = item.TransportationPrice;
                dr["MailTypeId"] = item.MailTypeId;
                dr["IsCoupon"] = item.IsCoupon;
                dr["CouponPrice"] = item.CouponPrice;
                dr["IsAddPrice"] = item.IsAddPrice;
                dr["AddPriceState"] = item.AddPriceState;
                dr["AddPrice"] = item.AddPrice;
                dr["ProductNumberList"] = item.ProductNumberList;
                dr["OrderGeneratedTime"] = item.OrderGeneratedTime;
                dr["OrderVerifyTime"] = item.OrderVerifyTime;
                dr["VerifyNameId"] = item.VerifyNameId;
                dr["AddressId"] = item.AddressId;
                dr["UserMessage"] = item.UserMessage;
                dr["UserIp"] = item.UserIp;
                dr["IsPayment"] = item.IsPayment;
                dr["PaymentTypeId"] = item.PaymentTypeId;
                dr["PaymentBankId"] = item.PaymentBankId;
                dr["PaymentPrice"] = item.PaymentPrice;
                dr["PaymentTime"] = item.PaymentTime;
                dr["PaymentOrderNumber"] = item.PaymentOrderNumber;
                dr["RefundTypeId"] = item.RefundTypeId;
                dr["LogisticsStateId"] = item.LogisticsStateId;
                dr["Logisticsnumber"] = item.Logisticsnumber;
                dr["PenskeLogistics"] = item.PenskeLogistics;
                dr["LogisticsRemarks"] = item.LogisticsRemarks;
                dr["OrderStateCodeId"] = item.OrderStateCodeId;
                dr["ProductOrderNumber"] = item.ProductOrderNumber;
                dr["IsDeliver"] = item.IsDeliver;
                dr["DeliverTime"] = item.DeliverTime;
                dr["DeliverUnitId"] = item.DeliverUnitId;
                dr["IsPrintDeliver"] = item.IsPrintDeliver;
                dr["AllocateUnitId"] = item.AllocateUnitId;
                dr["AllocateTime"] = item.AllocateTime;
                dr["AdminMessageId"] = item.AdminMessageId;
                dr["IsShow"] = item.IsShow;
                dr["Pro_AttrList"] = item.Pro_AttrList;
            }
            //调用FlexiGrid数据格式转换方法
            context.Response.Write(js.Serialize(new GetDataHelper().GetFlexiGridData(pageView, dt, (int)ds.Tables[1].Rows[0][0])));//ds.Tables[1].Rows[0][0] 这里是数据库表的记录行数  是第二张表的 在dao类中的最后方法中
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
